package gitlab_hook

import "atomgit.com/openlinksaas-org/proto-gen-go.git/events/events_gitlab"

type BuildHook struct {
	ObjectKind        string      `json:"object_kind"`
	Ref               string      `json:"ref"`
	Tag               bool        `json:"tag"`
	BeforeSha         string      `json:"before_sha"`
	Sha               string      `json:"sha"`
	BuildId           int64       `json:"build_id"`
	BuildName         string      `json:"build_name"`
	BuildStage        string      `json:"build_stage"`
	BuildStatus       string      `json:"build_status"`
	BuildStartedAt    customTime  `json:"build_started_at"`
	BuildFinishedAt   customTime  `json:"build_finished_at"`
	BuildDuration     float64     `json:"build_duration"`
	BuildAllowFailure bool        `json:"build_allow_failure"`
	ProjectId         int64       `json:"project_id"`
	ProjectName       string      `json:"project_name"`
	User              User        `json:"user"`
	Commit            BuildCommit `json:"commit"`
	Repository        Repository  `json:"repository"`
	Runner            Runner      `json:"runner"`
}

func (item *BuildHook) ToProtoBuf() *events_gitlab.BuildEvent {
	return &events_gitlab.BuildEvent{
		ObjectKind:        item.ObjectKind,
		Ref:               item.Ref,
		Tag:               item.Tag,
		BeforeSha:         item.BeforeSha,
		Sha:               item.Sha,
		BuildId:           item.BuildId,
		BuildName:         item.BuildName,
		BuildStage:        item.BuildStage,
		BuildStatus:       item.BuildStatus,
		BuildStartedAt:    item.BuildStartedAt.GetTimeStamp(),
		BuildFinishedAt:   item.BuildFinishedAt.GetTimeStamp(),
		BuildDuration:     float32(item.BuildDuration),
		BuildAllowFailure: item.BuildAllowFailure,
		ProjectId:         item.ProjectId,
		ProjectName:       item.ProjectName,
		User:              item.User.ToProtoBuf(),
		Commit:            item.Commit.ToProtoBuf(),
		Repository:        item.Repository.ToProtoBuf(),
		Runner:            item.Runner.ToProtoBuf(),
	}
}
